package com.cskaoyan.test;

import com.cskaoyan.utils.JDBCUtils;

import java.sql.*;

/**
 * 创建日期: 2022/04/21 11:21
 *
 * @author ciggar
 */
public class JDBC4Query {

    public static void main(String[] args) throws SQLException {

        // 获取连接
        Connection connection = JDBCUtils.getConnection();

        // 创建Statement对象
        Statement statement = connection.createStatement();

        // 发送SQL语句，获取结果集
        ResultSet resultSet = statement.executeQuery("select * from user where id > 1");

        // 解析结果集
        while (resultSet.next()) {

            int id = resultSet.getInt("id");
            String name = resultSet.getString("name");
            Date birthday = resultSet.getDate("birthday");

            System.out.println(id + ":" + name  + ":" + birthday);

        }

        // 关闭资源
        JDBCUtils.close(connection,statement,resultSet);

    }
}
